package suites.queue {
	import org.flexunit.asserts.assertEquals;
	import org.splink.library.queue.IQ;
	import org.splink.library.queue.IQable;
	import org.splink.library.queue.Q;
	import org.splink.library.queue.QEvent;

	/**
	 * @author Max Kugland
	 */
	public class QNestedTest extends AbstractQTest {
		
		
		[Test(async)]
		public function emptyNested() : void {
			handleAsync(1000);
			_q.add(new Q());			_q.add(new Q());			_q.add(new Q());
			_q.start();
		}

		[Test(async)]
		public function nested() : void {
			handleAsync(2000);
			
			_q.add(createQ(2)); //q0			_q.add(createQ(2)); //q3			_q.add(createQ(1)); //q6
			var completeOrder : Array = ["i-1","i-2","q-0","i-4","i-5","q-3","i-7","q-6"];
			
			Q.visit(_q, function(i : IQable) : void {
				i.register(QEvent.COMPLETE, function(e : QEvent):void {
					assertEquals(completeOrder.shift(), e.id);
				});
			});
			
			_q.start();
		}

		[Test(async)]
		public function deepNested() : void {
			handleAsync(3000);
			
			_q.add(createQ(1)); //q0
			
			var q1 : IQ = createQ(0); // q2			var q2 : IQ = createQ(1); // q3			var q3 : IQ = createQ(2); // q5			var q4 : IQ = createQ(3); // q8
			
			q1.add(q2);
			q1.add(q3);
			
			q2.add(q4);

			_q.add(q1);
			_q.add(createQ(1)); //q12
			
			var completeOrder : Array = ["i-1","q-0","i-4","i-9","i-10","i-11","q-8","q-3","i-6","i-7","q-5","q-2","i-13","q-12"];
			Q.visit(_q, function(i : IQable) : void {
				i.register(QEvent.COMPLETE, function(e : QEvent):void {
					assertEquals(completeOrder.shift(), e.id);
				});
			});
			
			_q.start();
		}
	}
}
